<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class BaseController extends Controller
{
    protected $time = null;

    public function __construct()
    {
        $this->time = time();
    }

    public function res($params = [])
    {
        return response()->json([
            'status' => isset($params['status']) ? $params['status'] : 200,
            'exception' => isset($params['exception']) ? $params['exception'] : 200,
            'code' => isset($params['code']) ? $params['code'] : 0,
            'message' => isset($params['message']) ? $params['message'] : '',
            'data' => !empty($params['data']) ? $params['data'] : (object)array(),
        ]);
    }

    public function ok($data = [], $msg = '')
    {
        if (is_array($data) && empty($data)) {
            $data = (object)array();
        }
        return $this->res(['message' => $msg,'data' => $data]);
    }

    public function err($code = 0, $status=200, $exception='', $msg='')
    {
        return $this->res(['status'=>$status,'exception'=>$exception,'code'=>$code,'message'=>$msg]);
    }
}
